<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="机构code" prop="baseCode">
        <el-input v-model="queryParams.baseCode" placeholder="请输入机构code" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机构主键" prop="deptId">
        <el-input v-model="queryParams.deptId" placeholder="请输入机构主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机构主键" prop="deptPkid">
        <el-input v-model="queryParams.deptPkid" placeholder="请输入机构主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目主键" prop="projectId">
        <el-input v-model="queryParams.projectId" placeholder="请输入项目主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="拌合站主键" prop="stationId">
        <el-input v-model="queryParams.stationId" placeholder="请输入拌合站主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="配方名称" prop="matchName">
        <el-input v-model="queryParams.matchName" placeholder="请输入配方名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="配方编号" prop="matchCode">
        <el-input v-model="queryParams.matchCode" placeholder="请输入配方编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="出料时间" prop="dischargeTime">
        <el-date-picker clearable v-model="queryParams.dischargeTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择出料时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出料温度" prop="dischargeTemperature">
        <el-input v-model="queryParams.dischargeTemperature" placeholder="请输入出料温度" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="溜槽温度" prop="sluiceTemperature">
        <el-input v-model="queryParams.sluiceTemperature" placeholder="请输入溜槽温度" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="盘重" prop="batchWeight">
        <el-input v-model="queryParams.batchWeight" placeholder="请输入盘重" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="搅拌时长" prop="mixingDuration">
        <el-input v-model="queryParams.mixingDuration" placeholder="请输入搅拌时长" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="沥青温度" prop="asphaltTemperature">
        <el-input v-model="queryParams.asphaltTemperature" placeholder="请输入沥青温度" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="油石比" prop="asphaltAggregateRatio">
        <el-input v-model="queryParams.asphaltAggregateRatio" placeholder="请输入油石比" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入库时间" prop="insertTime">
        <el-date-picker clearable v-model="queryParams.insertTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择入库时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目主键" prop="projectCode">
        <el-input v-model="queryParams.projectCode" placeholder="请输入项目主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="拌合站主键" prop="stationCode">
        <el-input v-model="queryParams.stationCode" placeholder="请输入拌合站主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="原数据标识" prop="originalId">
        <el-input v-model="queryParams.originalId" placeholder="请输入原数据标识" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['laboratoryManage:testSheetManage:query']">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"><el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['laboratoryManage:testSheetManage:add']">新增</el-button></el-col>
      <el-col :span="1.5"><el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['laboratoryManage:testSheetManage:edit']">修改</el-button></el-col>
      <el-col :span="1.5"><el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['laboratoryManage:testSheetManage:remove']">删除</el-button></el-col>
      <el-col :span="1.5"><el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['laboratoryManage:testSheetManage:export']">导出</el-button></el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="asphaltDataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据主键" align="center" prop="id" v-if="true" width="120" show-overflow-tooltip/>
      <el-table-column label="机构code" align="center" prop="baseCode" width="120" show-overflow-tooltip/>
      <el-table-column label="机构主键" align="center" prop="deptId" width="120" show-overflow-tooltip/>
      <el-table-column label="机构主键" align="center" prop="deptPkid" width="120" show-overflow-tooltip/>
      <el-table-column label="项目主键" align="center" prop="projectId" width="120" show-overflow-tooltip/>
      <el-table-column label="拌合站主键" align="center" prop="stationId" width="120" show-overflow-tooltip/>
      <el-table-column label="级配类型" align="center" prop="matchType" width="120" show-overflow-tooltip/>
      <el-table-column label="配方名称" align="center" prop="matchName" width="120" show-overflow-tooltip/>
      <el-table-column label="配方编号" align="center" prop="matchCode" width="120" show-overflow-tooltip/>
      <el-table-column label="出料时间" align="center" prop="dischargeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dischargeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出料温度" align="center" prop="dischargeTemperature" width="120" show-overflow-tooltip/>
      <el-table-column label="溜槽温度" align="center" prop="sluiceTemperature" width="120" show-overflow-tooltip/>
      <el-table-column label="盘重" align="center" prop="batchWeight" width="120" show-overflow-tooltip/>
      <el-table-column label="搅拌时长" align="center" prop="mixingDuration" width="120" show-overflow-tooltip/>
      <el-table-column label="沥青温度" align="center" prop="asphaltTemperature" width="120" show-overflow-tooltip/>
      <el-table-column label="油石比" align="center" prop="asphaltAggregateRatio" width="120" show-overflow-tooltip/>
      <el-table-column label="入库时间" align="center" prop="insertTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.insertTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产类型,0:来料，1：进料" align="center" prop="productionType" width="180" show-overflow-tooltip/>
      <el-table-column label="项目主键" align="center" prop="projectCode" width="120" show-overflow-tooltip/>
      <el-table-column label="拌合站主键" align="center" prop="stationCode" width="120" show-overflow-tooltip/>
      <el-table-column label="原数据标识" align="center" prop="originalId" width="120" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['laboratoryManage:testSheetManage:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['laboratoryManage:testSheetManage:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改沥青拌合站数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="机构code" prop="baseCode">
          <el-input v-model="form.baseCode" placeholder="请输入机构code" />
        </el-form-item>
        <el-form-item label="机构主键" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入机构主键" />
        </el-form-item>
        <el-form-item label="机构主键" prop="deptPkid">
          <el-input v-model="form.deptPkid" placeholder="请输入机构主键" />
        </el-form-item>
        <el-form-item label="项目主键" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目主键" />
        </el-form-item>
        <el-form-item label="拌合站主键" prop="stationId">
          <el-input v-model="form.stationId" placeholder="请输入拌合站主键" />
        </el-form-item>
        <el-form-item label="配方名称" prop="matchName">
          <el-input v-model="form.matchName" placeholder="请输入配方名称" />
        </el-form-item>
        <el-form-item label="配方编号" prop="matchCode">
          <el-input v-model="form.matchCode" placeholder="请输入配方编号" />
        </el-form-item>
        <el-form-item label="出料时间" prop="dischargeTime">
          <el-date-picker clearable v-model="form.dischargeTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择出料时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出料温度" prop="dischargeTemperature">
          <el-input v-model="form.dischargeTemperature" placeholder="请输入出料温度" />
        </el-form-item>
        <el-form-item label="溜槽温度" prop="sluiceTemperature">
          <el-input v-model="form.sluiceTemperature" placeholder="请输入溜槽温度" />
        </el-form-item>
        <el-form-item label="盘重" prop="batchWeight">
          <el-input v-model="form.batchWeight" placeholder="请输入盘重" />
        </el-form-item>
        <el-form-item label="搅拌时长" prop="mixingDuration">
          <el-input v-model="form.mixingDuration" placeholder="请输入搅拌时长" />
        </el-form-item>
        <el-form-item label="沥青温度" prop="asphaltTemperature">
          <el-input v-model="form.asphaltTemperature" placeholder="请输入沥青温度" />
        </el-form-item>
        <el-form-item label="油石比" prop="asphaltAggregateRatio">
          <el-input v-model="form.asphaltAggregateRatio" placeholder="请输入油石比" />
        </el-form-item>
        <el-form-item label="入库时间" prop="insertTime">
          <el-date-picker clearable v-model="form.insertTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择入库时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目主键" prop="projectCode">
          <el-input v-model="form.projectCode" placeholder="请输入项目主键" />
        </el-form-item>
        <el-form-item label="拌合站主键" prop="stationCode">
          <el-input v-model="form.stationCode" placeholder="请输入拌合站主键" />
        </el-form-item>
        <el-form-item label="原数据标识" prop="originalId">
          <el-input v-model="form.originalId" placeholder="请输入原数据标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAsphaltData, getAsphaltData, delAsphaltData, addAsphaltData, updateAsphaltData } from "@/api/zhgd/asphaltData";

export default {
  name: "testSheetManage",//试验单管理
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 沥青拌合站数据表格数据
      asphaltDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseCode: undefined,
        deptId: undefined,
        deptPkid: undefined,
        projectId: undefined,
        stationId: undefined,
        matchType: undefined,
        matchName: undefined,
        matchCode: undefined,
        dischargeTime: undefined,
        dischargeTemperature: undefined,
        sluiceTemperature: undefined,
        batchWeight: undefined,
        mixingDuration: undefined,
        asphaltTemperature: undefined,
        asphaltAggregateRatio: undefined,
        insertTime: undefined,
        productionType: undefined,
        projectCode: undefined,
        stationCode: undefined,
        originalId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "数据主键不能为空", trigger: "blur" }
        ],
        baseCode: [
          { required: true, message: "机构code不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "机构主键不能为空", trigger: "blur" }
        ],
        deptPkid: [
          { required: true, message: "机构主键不能为空", trigger: "blur" }
        ],
        projectId: [
          { required: true, message: "项目主键不能为空", trigger: "blur" }
        ],
        stationId: [
          { required: true, message: "拌合站主键不能为空", trigger: "blur" }
        ],
        matchType: [
          { required: true, message: "级配类型不能为空", trigger: "change" }
        ],
        matchName: [
          { required: true, message: "配方名称不能为空", trigger: "blur" }
        ],
        matchCode: [
          { required: true, message: "配方编号不能为空", trigger: "blur" }
        ],
        dischargeTime: [
          { required: true, message: "出料时间不能为空", trigger: "blur" }
        ],
        dischargeTemperature: [
          { required: true, message: "出料温度不能为空", trigger: "blur" }
        ],
        sluiceTemperature: [
          { required: true, message: "溜槽温度不能为空", trigger: "blur" }
        ],
        batchWeight: [
          { required: true, message: "盘重不能为空", trigger: "blur" }
        ],
        mixingDuration: [
          { required: true, message: "搅拌时长不能为空", trigger: "blur" }
        ],
        asphaltTemperature: [
          { required: true, message: "沥青温度不能为空", trigger: "blur" }
        ],
        asphaltAggregateRatio: [
          { required: true, message: "油石比不能为空", trigger: "blur" }
        ],
        insertTime: [
          { required: true, message: "入库时间不能为空", trigger: "blur" }
        ],
        productionType: [
          { required: true, message: "生产类型,0:来料，1：进料不能为空", trigger: "change" }
        ],
        projectCode: [
          { required: true, message: "项目主键不能为空", trigger: "blur" }
        ],
        stationCode: [
          { required: true, message: "拌合站主键不能为空", trigger: "blur" }
        ],
        originalId: [
          { required: true, message: "原数据标识不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询沥青拌合站数据列表 */
    getList() {
      this.loading = true;
      listAsphaltData(this.queryParams).then(response => {
        this.asphaltDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        baseCode: undefined,
        deptId: undefined,
        deptPkid: undefined,
        projectId: undefined,
        stationId: undefined,
        matchType: undefined,
        matchName: undefined,
        matchCode: undefined,
        dischargeTime: undefined,
        dischargeTemperature: undefined,
        sluiceTemperature: undefined,
        batchWeight: undefined,
        mixingDuration: undefined,
        asphaltTemperature: undefined,
        asphaltAggregateRatio: undefined,
        insertTime: undefined,
        productionType: undefined,
        projectCode: undefined,
        stationCode: undefined,
        originalId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加沥青拌合站数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getAsphaltData(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改沥青拌合站数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateAsphaltData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addAsphaltData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除沥青拌合站数据编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delAsphaltData(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zhgd/asphaltData/export', {
        ...this.queryParams
      }, `asphaltData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
